package com.weitu.workflow.flowBusiness.service.impl;

import com.weitu.workflow.definition.constant.FlowDefConstants;
import com.weitu.workflow.flowBusiness.entity.FlowBusiness;
import com.weitu.workflow.flowBusiness.mapper.FlowBusinessMapper;
import com.weitu.workflow.flowBusiness.service.FlowBusinessService;
import com.weitu.workflow.flowManagement.entity.WorkItemInfo;
import com.weitu.workflow.flowManagement.entity.WorkflowInstance;
import com.weitu.workflow.flowManagement.entity.WorkflowReview;
import com.weitu.workflow.flowManagement.mapper.FlowManagementMapper;
import com.weitu.workflow.flowManagement.service.FlowManagementService;
import org.apache.log4j.Logger;
import org.fireflow.engine.IProcessInstance;
import org.fireflow.engine.RuntimeContext;
import org.fireflow.engine.definition.WorkflowDefinition;
import org.fireflow.model.FormTask;
import org.fireflow.model.Task;
import org.fireflow.model.net.Activity;
import org.fireflow.model.net.Node;
import org.fireflow.model.net.Synchronizer;
import org.fireflow.model.resource.Form;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 流程业务标识管理Service实现类
 * Created by Administrator on 2017/3/17.
 */
@Service
public class FlowBusinessServiceImpl implements FlowBusinessService {
    @Autowired
    private FlowBusinessMapper flowBusinessMapper;//流程业务标识管理mapper

    /***
     * 根据流程业务数量
     * @param paramMap
     * @return
     */
    public int queryFlowBusinessCount(Map<String, Object> paramMap){
        return this.flowBusinessMapper.queryFlowBusinessCount(paramMap);
    }
    /***
     * 根据流程业务数据列表
     * @param paramMap
     * @return
     */
    public List<FlowBusiness> queryFlowBusinessList(Map<String, Object> paramMap){
        return this.flowBusinessMapper.queryFlowBusinessList(paramMap);
    }
    /***
     * 根据业务标识查询流程业务信息
     * @param identity
     * @return
     */
    public FlowBusiness queryFlowBusinessByIdentity(String identity){
        return this.flowBusinessMapper.queryFlowBusinessByIdentity(identity);
    }
    /***
     * 添加流程业务信息
     * @param paramMap
     * @return
     */
    public boolean addFlowBusiness(Map<String, Object> paramMap){
        return this.flowBusinessMapper.addFlowBusiness(paramMap);
    }
    /***
     * 查询流程业务标识集合
     * @return
     */
    public List<FlowBusiness> queryFlowBusinessIdentityList(){
        return this.flowBusinessMapper.queryFlowBusinessIdentityList();
    }
    /**
     * 根据流程id删除业务关联
     * @param processId
     * @return
     */
    public boolean deleteBusinessIdentityAndProcessId(String processId){
        return this.flowBusinessMapper.deleteBusinessIdentityAndProcessId(processId);
    }
    /**
     * 保存业务标识以及对应的工作流
     * @param map
     * @return
     */
    public boolean addBusinessIdentityAndProcessId(Map<String,Object> map){
        int flag = this.flowBusinessMapper.addBusinessIdentityAndProcessId(map);
        if(flag<1){
            return false;
        }
        return true;
    }
    /**
     * 查询全部流程业务标识集合
     * @return
     */
    public List<FlowBusiness> queryFlowBusinessIdentityListNotWorkFlow(){
        return this.flowBusinessMapper.queryFlowBusinessIdentityListNotWorkFlow();
    }
    /**
     * 查询流程业务标识集合（没有关联工作流）
     * @return
     */
    public List<FlowBusiness> queryFlowBusinessIdentityListNotWorkFlow(String processId){
        return this.flowBusinessMapper.queryFlowBusinessIdentityListNotWorkFlow(processId);
    }
    /**
     * 根据流程标识查询业务标识集合
     * @return
     */
    public List<FlowBusiness> queryFlowBusinessIdentityByProcessId(String processId){
        return this.flowBusinessMapper.queryFlowBusinessIdentityByProcessId(processId);
    }
    /**
     * 查询该业务标识是否加入工作流
     * @param map
     * @return
     */
    public boolean queryFlowBusinessIsInWorkFlow(Map<String,Object> map){
        int flag = this.flowBusinessMapper.queryFlowBusinessIsInWorkFlow(map);
        if(flag>=1){
            return false;
        }

        return true;
    }

    /**
     * 更新流程业务信息
     * @param map
     * @return
     */
    public boolean updateFlowBusiness(Map<String,Object> map){
        int flag = this.flowBusinessMapper.updateFlowBusiness(map);
        if(flag<1){
            return false;
        }
        return true;
    }
    /**
     * 删除流程业务信息
     * @param map
     * @return
     */
    public boolean deleteFlowBusiness(Map<String,Object> map){
        int flag = this.flowBusinessMapper.deleteFlowBusiness(map);
        if(flag<1){
            return false;
        }
        return true;
    }
}
